<template>
  <div>
    <el-dialog
      v-loading="loading"
      class="mt-dialog"
      :title="domain + title"
      :visible.sync="dialogVisible"
      :close-on-press-escape="false"
      top="80px"
      width="1280px"
      @close="close"
    >
      <div>

        <el-form ref="form" :model="data" label-width="200px" size="mini">
          <el-form-item label="网站TAG">
            <el-input v-model="data.tag" />
          </el-form-item>
          <el-form-item label="详细备注">
            <el-input v-model="data.note" type="textarea" :rows="5" />
          </el-form-item>
          <el-form-item label="网站状态">
            <el-select v-model="data.upload_state" clearable placeholder="状态">
              <el-option
                v-for="item in uploadStateOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="起始单号">
            <el-input v-model="data.start_order_number" />
          </el-form-item>
          <el-form-item label="产品最低价">
            <el-input v-model="data.price_min" />
          </el-form-item>
          <el-form-item label="网站币种">
            <el-input v-model="data.currency_code" />
          </el-form-item>
          <el-form-item label="上传最低价">
            <el-input v-model="data.upload_min_price" />
          </el-form-item>
          <el-form-item label="上传最高价">
            <el-input v-model="data.upload_max_price" />
          </el-form-item>
          <el-form-item label="paypal api account">
            <el-input v-model="data.paypal_api_account" />
          </el-form-item>
          <el-form-item label="是否运行">
            <el-switch
              v-model="data.isEnable"
              active-color="#13ce66"
              inactive-color="#ff4949"
            />
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-tag style="float: left;margin-left: 10px">网站ID: {{ website_id }}</el-tag>
        <el-button type="default" @click="close">取消</el-button>
        <el-button type="danger" @click="handleModify">确认</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { Get, Put, GetWebsiteStateOptions } from '@/api/erp/elicink/website'

export default {
  name: 'Modifywebsite',
  props: ['pstVisible', 'website_id', 'domain'],
  data() {
    return {
      title: '网站常用信息修改',
      uploadStateOptions: GetWebsiteStateOptions(),
      dialogVisible: false,
      loading: false,
      data: []
    }
  },
  watch: {
    pstVisible(v) {
      this.dialogVisible = v
      if (v) {
        this.getList()
      }
    }
  },
  methods: {
    getList() {
      this.loading = true
      Get(this.website_id, null)
        .then(response => {
          this.data = response.data
          this.loading = false
        }).catch(err => {
          console.log(err)
          this.loading = false
        })
    },
    handleModify() {
      Put(this.data.id, {
        domain: this.data.domain,
        code: this.data.code,
        upload_state: this.data.upload_state,
        type: this.data.type,
        tag: this.data.tag,
        note: this.data.note,
        price_increace: this.data.price_increace,
        price_min: this.data.price_min,
        upload_min_price: this.data.upload_min_price,
        upload_max_price: this.data.upload_max_price,
        m_frequency: this.data.m_frequency,
        ds_username: this.data.ds_username,
        ds_password: this.data.ds_password,
        start_order_number: this.data.start_order_number,
        token: this.data.token,
        paypal_api_account: this.data.paypal_api_account,
        currency_code: this.data.currency_code,
        isEnable: this.data.isEnable
      }).then(response => {
        this.getList()
        this.notify('更新成功')
        this.close()
      })
    },
    notify(message, duration) {
      this.$notify({
        title: '成功',
        message: message,
        type: 'success',
        duration: duration || 2000
      })
    },
    close() {
      this.dialogVisible = false
      this.$emit('closeMyDialog', false)
    }
  }
}
</script>

<style scoped>

  .top >>> .input-with-select .el-input-group__prepend {
    background-color: #fff;
  }

  .input-with-select {
    width: calc(100% - 200px);
  }

  .app-container >>> .el-dialog {
    margin-top: 48px !important;
    margin-bottom: 5px;
  }

  .mt-dialog >>> .el-transfer-panel {
    width: calc(50% - 60px);
  }

  .mt-form >>> .el-select {
    width: 100%;
  }

  .mt-form >>> .el-input__inner {
    width: 100%;
  }

  .mt-dialog >>> .el-dialog {
    margin: 10px auto !important;
  }

  .mt-dialog >>> .el-dialog__body {
    padding-bottom: 60px;
    padding-top: 5px;
  }

  .top >>> .el-select {
    width: 300px;
  }
</style>
